package com.xuecheng.content.api;

import com.xuecheng.base.model.Result;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.TeachplanMedia;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping()
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    //GET /teachplan/22/tree-nodes

    /**
     * 获取课程计划
     * @author hjh
     * @date 2023/5/6 16:18
     * @param courseId
     * @return List<TeachplanDto>
     */

    @GetMapping("/teachplan/{courseId}/tree-nodes")
    @ApiOperation("获取课程计划")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.getTreeNodes(courseId);
    }

//    ### 新增课程计划--章,当grade为1时parentid为0
//    POST /teachplan

    /**
     * 新增课程计划
     * @author hjh
     * @date 2023/5/6 16:18
     * @param saveTeachplanDto
     */

    @ApiOperation("新增课程计划--章,当grade为1时parentid为0")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto){
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

//    Request URL: /content/teachplan/246
//    Request Method: DELETE

    /**
     * 通过课程计划id删除课程计划
     * @author hjh
     * @date 2023/5/6 21:47
     * @param teachplanId
     * @return Result
     */

    @DeleteMapping("/teachplan/{teachplanId}")
    public Result deleteTeachplan(@PathVariable @NotEmpty(message = "课程id不能为空")Long teachplanId){
        return teachplanService.deleteTeachplan(teachplanId);
    }


//    Request URL: http://localhost:8601/api/content/teachplan/movedown/43
//    Request Method: POST

    @PostMapping("/teachplan/{movetype}/{id}")
    @ApiOperation("小节下移")
    public Result movedown(@PathVariable String movetype,@PathVariable Long id){
        teachplanService.move(movetype,id);
        return null;
    }



    @PostMapping("/teachplan/association/media")
    @ApiOperation("课程计划和媒资信息绑定")
    public TeachplanMedia associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        return teachplanService.associationMedia(bindTeachplanMediaDto);
    }

//    /teachplan/association/media/{teachPlanId}/{mediaId}
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    @ApiOperation("删除课程计划关联媒资信息")
    public Result deleteAssociationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        return teachplanService.deleteAssociationMedia(teachPlanId,mediaId);
    }

}
